package com.dries.portal.module.coupon.enums;

import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * @Description: 商品类型枚举
 * @Author ZSY
 * @createTime 2020/7/29 13:12
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum GoodsType {

    WENYU(1, "文娱"),
    SHENGXIAN(2, "生鲜"),
    JIAJU(3, "家居"),
    OTHERS(4, "其他"),
    ALL(5,"全品类");

    private Integer code;

    private String description;

    @JsonValue
    public String getDescription() {
        return description;
    }

    public static GoodsType of(Integer code) {
        Objects.requireNonNull(code);

        return Stream.of(values())
                .filter(e -> e.getCode().equals(code))
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException(code + "not exists"));

    }

}
